<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun1(){
				alert("按钮1被点击了")
			}
		</script>
	</head>
	<body>
		<!-- //方法一:直接添加事件 -->
		<button onclick="fun1()">按钮1</button>
		<button id="b2">按钮2</button>
		<button class="b3">按钮3</button>
		<button id="b4">按钮4</button>
		<script type="text/javascript">
			//方法二:获得元素,为事件属性赋值
			let b2=document.getElementById("b2")
			b2.onclick=fun2;
			function fun2(){
				alert("按钮2被点击了")
			}	
			//获得的元素是个数组,需要指定下标
			//方法三:获得元素,为元素添加赋值
			let b3=document.getElementsByClassName("b3")[0]
			b3.addEventListener('click',fun3)
			function fun3(){
				alert("按钮3被点击了")
			}
			
			let b4=document.getElementById("b4")
			b4.onclick=fun4
			function fun4(){
				alert("按钮3不能被点击了")
				let b3=document.getElementsByClassName("b3")[0]
				b3.removeEventListener('click',fun3)
			}
				
				
				
				
				
			
		</script>
	</body>
</html>
